package tt.dz.service.imp.sys;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tt.dz.dao.ext.dic.OmsDicForwardSrvInfoDao;
import tt.dz.entity.dic.OmsDicForwardSrvInfo;
import tt.dz.service.sys.OmsDicForwardSrvInfoService;
@Service @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class OmsDicForwardSrvInfoServiceImpl  implements OmsDicForwardSrvInfoService{
	
	@Resource
	OmsDicForwardSrvInfoDao omsDicForwardSrvInfoDao;

	@Override
	public OmsDicForwardSrvInfo findOneExample(OmsDicForwardSrvInfo obj,
			String order, String sortVal) {
		return omsDicForwardSrvInfoDao.findOneExample(obj, order, sortVal);
	}

	@Override
	public List<OmsDicForwardSrvInfo> findList(OmsDicForwardSrvInfo obj, Integer pageNo, Integer pageSize,String sortName, Integer sortVal) {
		return omsDicForwardSrvInfoDao.findExample(obj, pageNo, pageSize, sortName, sortVal);
	}

	@Override
	public int save(OmsDicForwardSrvInfo obj) {
		return omsDicForwardSrvInfoDao.save(obj);
	}

	@Override
	public int updateObject(OmsDicForwardSrvInfo obj) {
		return omsDicForwardSrvInfoDao.updateObject(obj);
	}

	@Override
	public int logicDelete(OmsDicForwardSrvInfo obj) {
		return omsDicForwardSrvInfoDao.LogicDeleteObject(obj);
	}

	@Override
	public int bindChargers(String forward_srv_id, List<String> chargerIds) {
		//for循环，update桩表
		try {
			StringBuilder sb = new StringBuilder("update oms_charger  set  forward_srv_id = "+forward_srv_id+" where charger_id in (");
			for(String chargerId:chargerIds){
				sb.append("'"+chargerId+"',");
			}
			sb.deleteCharAt(sb.length()-1);
			sb.append(")");
			omsDicForwardSrvInfoDao.exec(sb.toString());
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

	@Override
	public List<OmsDicForwardSrvInfo> findAllChargersByForwardId(OmsDicForwardSrvInfo omsDicForwardSrvInfo,
			Integer pageNo, Integer pageSize, String sortName, Integer sortVal) {
//		return omsDicForwardSrvInfoDao.findListByPageAndGroupAndOrderAndCondition(omsDicForwardSrvInfo, condition, pageNo, pageSize, sortName, sortVal, groupByStrs)
		 return null;
	}

	@Override
	public int unBindChargers(List<String> chargerIdList) {
		//for循环，update桩表
		try {
			StringBuilder sb = new StringBuilder("update oms_charger  set  forward_srv_id = 0 where charger_id in (");
			for(String chargerId:chargerIdList){
				sb.append("'"+chargerId+"',");
			}
			sb.deleteCharAt(sb.length()-1);
			sb.append(")");
			omsDicForwardSrvInfoDao.exec(sb.toString());
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}
}
